define(['jquery',
        'jqureyui',
        'underscore',
        'handlebar',
        'backbone',
        'GlobalConfiguration',
        '../../collection/filters/Cfilters',
        'views/product/VProducts',
        'text!../../../templates/filters/brandFilter.html'
],
        function ($,
                jqueryui,
                _,
                Handlebar,
                Backbone,
                GConfigs,
                CollectoionFilter,
                VProducts,
                TemplateFilter
                ) {
            var arrAvailableProducts = [];
            var VFilter = Backbone.View.extend({               
                el: $('.left-panel-items'),
                initialize: function () {                                       
                    var that = this;
                    var collectoionFilter = new CollectoionFilter();
                  
                    collectoionFilter.fetch({                        
                        success: function (resp) {
                            //debugger;
                            that.render(resp);
                        },
                        error: function(err) {                           
                            console.log("%c ERROR: in fetching Filter Service", "color:red,font-size:samll", err)
                        }
                    });
                },
                render: function (data) {                   
                    var filterTemplate = Handlebars.compile(TemplateFilter);
                    var filterTemplateDOM = filterTemplate(data.toJSON());
                    this.$el.html(filterTemplateDOM)                                                          
                    
                },
                events: {
                    'click ul.brand-filter-ul li input.brand-radiokBtn': 'filterSearchResultsByBrand'
                },
                filterSearchResultsByBrand: function (ev) {
                    var reqObj = {};
                    var URL = GConfigs.CONSTANTS.PROTOCOL + "://" +
                              GConfigs.CONSTANTS.HOST_NAME + ":" +
                              GConfigs.CONSTANTS.PORT_NO +
                              GConfigs.CONSTANTS.REST_PATH +
                              GConfigs.API.filterSearchedProducts;
                                     
                    reqObj.brandName = ev.currentTarget.value,
                    reqObj.cityName = window.placeId,
                    reqObj.srchItem = window.searchItem
                   // debugger;
                   

                    $.ajax({                                              
                        url: URL,
                        dataType: 'json',
                        data: reqObj,
                        success: function (resp) {                                                                                
                             var filtertedModel = new Backbone.Model(resp.rows);
                             var vProducts = new VProducts();
                             vProducts.render(filtertedModel)
                        },
                        error:function(){

                        }
                    })
                }
            });
            return VFilter;
        });

